﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Titan;
using Titan.MySql;
using Titan.SqlTracer;
using System.Configuration;

namespace StockMatch.Host
{
    public class Environment
    {
        public static ISqlProvider SqlProvider;
        public static ISqlTracer[] SqlTracers;

        static Environment()
        {
            SqlProvider = new MySqlSqlProvider();
            SqlTracers = new FileSqlTracer[] { };
        }
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["ConnectionString"]))
                {
                    throw new  Exception("请先配置数据库");
                }
                return ConfigurationManager.AppSettings["ConnectionString"];
            }
        }

        public static IDbSession OpenSession()
        {
            IDbSession session = new DbSession(SqlProvider, ConnectionString, SqlTracers);
            session.Open();
            return session;
        }

    }
}
